package com.atech.ace.dao;

// Generated Feb 22, 2012 1:06:24 PM by Hibernate Tools 3.2.4.GA

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;

import com.atech.ace.entity.Orderitem;

/**
 * Home object for domain model class Orderitem.
 * @see com.atech.ace.entity.Orderitem
 * @author Hibernate Tools
 */
public class OrderitemHome {

	private static final Log log = LogFactory.getLog(OrderitemHome.class);

	private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
	public void persist(Orderitem transientInstance) {
		log.debug("persisting Orderitem instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Orderitem instance) {
		log.debug("attaching dirty Orderitem instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Orderitem instance) {
		log.debug("attaching clean Orderitem instance");
		try {
			sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Orderitem persistentInstance) {
		log.debug("deleting Orderitem instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Orderitem merge(Orderitem detachedInstance) {
		log.debug("merging Orderitem instance");
		try {
			Orderitem result = (Orderitem) sessionFactory.getCurrentSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Orderitem findById(java.lang.Integer id) {
		log.debug("getting Orderitem instance with id: " + id);
		try {
			Orderitem instance = (Orderitem) sessionFactory.getCurrentSession()
					.get("com.atech.ace.entity.Orderitem", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Orderitem instance) {
		log.debug("finding Orderitem instance by example");
		try {
			List results = sessionFactory.getCurrentSession().createCriteria(
					"com.atech.ace.entity.Orderitem").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
}
